package Experiment3;

import java.io.FileNotFoundException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Scanner;

import edu.princeton.cs.algs4.Edge;
import edu.princeton.cs.algs4.Point2D;

/** 
 * <p>从指定文件中读取地图数据
 * 
 * @author Chen Junjie
 */
public class InputData {
    private EuclidienGraph graph;
    private int point_num;
    private int edge_num;


    public InputData(String name){   
        Path path=Paths.get(".\\src\\Experiment3\\"+name);
        Scanner sc;
        try{
            sc=new Scanner(path.toFile());
            point_num=sc.nextInt();
            edge_num=sc.nextInt();

            graph=new EuclidienGraph(point_num);
            
            Point2D points[]=new Point2D[point_num];
            for(int i=0;i<point_num;i++){
                int k=sc.nextInt();
                points[k]=new Point2D(sc.nextDouble(), sc.nextDouble());
                graph.defineVertice(k, points[k]);
            }
            
            
            for(int i=0;i<edge_num;i++){
                int v1=sc.nextInt();
                int v2=sc.nextInt();
                
                Edge edge=new Edge(v1,v2,points[v1].distanceTo(points[v2]));
                graph.addEdge(edge);
            }

        }catch(FileNotFoundException e){
            System.err.println(e);
        }
    }

    public EuclidienGraph getGraph(){
        return graph;
    }
}
